//
//  SRIDReaderTestViewController.m
//  SunriseReaderDemo
//
//  Created by 田宇 on 2024/11/27.
//  Copyright © 2024 Chenfan. All rights reserved.
//

#import "SRIDReaderTestViewController.h"

@interface SRIDReaderTestViewController ()
{
    UIScrollView * _contentView;
}
@end

@implementation SRIDReaderTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _contentView = [[UIScrollView alloc] init];
    _contentView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:_contentView];
    
    //正面信息
    UIImageView *idCardView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 0, self.view.frame.size.width, 330)];
    UIImage *image = _readerController.IDCardFrontImg;
    idCardView.frame = CGRectMake(0, 88, image.size.width, image.size.height);
    idCardView.image = image;
    [_contentView addSubview:idCardView];
    
    //背面国徽
    UIImageView *IDCardBackImgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 350, self.view.frame.size.width, 330)];
    UIImage *backImg = _readerController.IDCardBackImg;
    IDCardBackImgView.image = backImg;
    IDCardBackImgView.frame = CGRectMake(0, idCardView.frame.origin.y + idCardView.frame.size.height + 60, backImg.size.width, backImg.size.height);
    [_contentView addSubview:IDCardBackImgView];
    
    UIImageView *IDCardImgView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 700, self.view.frame.size.width, 330)];
    UIImage *IDCardImage = _readerController.IDCardImg;
    IDCardImgView.image = IDCardImage;
    IDCardImgView.frame = CGRectMake(0, IDCardBackImgView.frame.origin.y + IDCardBackImgView.frame.size.height + 60, IDCardImage.size.width, IDCardImage.size.height);

    [_contentView addSubview:IDCardImgView];
    
    
    //有些参数没有，需要上游设置
    _readerController.logInfo.bizTypeCode = @"1111";
    _readerController.logInfo.employeeId = @"1111";
    //设置完毕后调用toDictionary方法
    NSDictionary *parameters = [_readerController.logInfo toDictionary];
    [_readerController recordSdkLogWithParameters:parameters completionBlock:^(NSDictionary *resultDic, NSURLResponse * _Nonnull response, NSError * _Nonnull error) {
        NSLog(@"%@",resultDic.description);
    }];
    // Do any additional setup after loading the view.
}


- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    // 假设你有一个 UIScrollView 和一个自定义的内容视图
    [self adjustScrollViewHeight];
}

- (void)adjustScrollViewHeight {
    // 获取内容视图的总高度（假设内容视图的子视图已经全部添加）
    CGFloat contentHeight = 0;
    for (UIView *subview in _contentView.subviews) {
        contentHeight += CGRectGetHeight(subview.frame);  // 累加每个子视图的高度
    }

    // 更新 UIScrollView 的 contentSize
    _contentView.contentSize = CGSizeMake(_contentView.frame.size.width, contentHeight + 200);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
